function acceptReqExportTicket() {
	if (!validate()) {
		return false;
	}
	
	promptConfirm(_("Accept"),_('Are you sure to accept this request? cannot edit after accepted'), function() {
		submitAcceptReqExportTicket(); 
		return true;
	},'YesNo','warn',_('No'));
	
	
}
function submitAcceptReqExportTicket() {
	var data = buildDataAcceptReqExportTicket();
	$.ajax({
		type:		"POST",
		url:		"../EwhExportDrugMaterial/AcceptReqExTicketAjax?set_ajax_view",		
		dataType:   "json",	
		data : data,
		beforeSend: function() {
			$('div#phaEwhReqExpLoaderDiv').show();		
		},
		success: 	function(data) {
			if (data.error.code ==  'OK') {	
				$("span#expTicketCodeText").html(data.result.code);
				$("#expTicketIdHidden").val(data.result.id);
				/*
				$("#acceptBtn").attr('disabled','disabled');
				$("input[name='pickDrugItemBtn']").each(function() {
					$(this).attr('disabled','disabled');
				})
				*/
											
			} else {
				displayError(data.error.mess);				
			}
			$('div#phaEwhReqExpLoaderDiv').hide();
		}
		});		
}
function submitRejectReqExportTicket() {
	var data = buildDataForRejectExTicket();
	$.ajax({
		type:		"POST",
		url:		"../EwhExportDrugMaterial/RejectReqExTicketAjax?set_ajax_view",		
		dataType:   "json",	
		data : data,
		beforeSend: function() {
			$('div#phaEwhReqExpLoaderDiv').show();		
		},
		success: 	function(data) {
			if (data.error.code ==  'OK') {
				$("#expTicketIdHidden").val(data.result.id);
				window.location =  "../EwhExportQueue/DisplayQueue";
			} else {
				displayError(data.error.mess);				
			}
			$('div#phaEwhReqExpLoaderDiv').hide();
		}
		});	
}
function rejectReqExportTicket() {
	if (!validate()) {
		return false;
	}
	
	promptConfirm(_("Reject"),_('Are you sure to reject this request?'), function() {
		submitRejectReqExportTicket(); 
		return true;
	},'YesNo','warn',_('No'));
	
	
}

function validate() {
	 $('#statusMessageExTicket').html('');
	 
	if (!checkDay($('#datedd'),true,'','#statusMessageExTicket' )) {
			$('#statusMessageExTicket').show();	
			return false;
	}	
		
	if (!checkMonth($('#datemm'),true,'','#statusMessageExTicket')) {
		$('#statusMessageExTicket').show();
		return false;
	} 

	var res 	= 	checkDate($('#dateyyyy'),
			$('#datemm'),
			$('#datedd'), true, '', '#statusMessageExTicket', false);	

	if(!res){	
		$('#statusMessageExTicket').show();
		return false;
	}
	
	return true;
}

function buildDataAcceptReqExportTicket() {
	var d = new Date();
	var currHour = (d.getHours() < 10 ? '0' + d.getHours(): d.getHours());
	var currMin = (d.getMinutes() < 10 ? '0' + d.getMinutes(): d.getMinutes());
	var currSeconds = (d.getSeconds() < 10 ? '0' + d.getSeconds(): d.getSeconds());
	var date = $('#dateyyyy').val() 
		+ '-' 
		+ $('#datemm').val()
		+ '-'
		+ $('#datedd').val()
		+ ' '
		+ currHour
		+ ':'
		+ currMin
		+ ':'
		+ currSeconds;
	var data = '';
	data += 'expTicketId=' + $('#expTicketIdHidden').val();
	data += '&reqExTicketId=' + $("#reqTicketIdHidden").val();
	data += '&appDate=' + date;
	data += '&appNote=' + $("#expTicketNote").val();
	data += '&' + $("#pickedDrugMaterialForm").serialize();
	
	return data;
}
function buildDataForRejectExTicket() {
	var d = new Date();
	var currHour = (d.getHours() < 10 ? '0' + d.getHours(): d.getHours());
	var currMin = (d.getMinutes() < 10 ? '0' + d.getMinutes(): d.getMinutes());
	var currSeconds = (d.getSeconds() < 10 ? '0' + d.getSeconds(): d.getSeconds());
	var date = $('#dateyyyy').val() 
		+ '-' 
		+ $('#datemm').val()
		+ '-'
		+ $('#datedd').val()
		+ ' '
		+ currHour
		+ ':'
		+ currMin
		+ ':'
		+ currSeconds;
	var data = '';
	data += 'expTicketId=' + $('#expTicketIdHidden').val();
	data += '&reqExTicketId=' + $("#reqTicketIdHidden").val();
	data += '&appDate=' + date;
	data += '&appNote=' + $("#expTicketNote").val();	
	return data;
}

function pickDrug(reqExticketDetailId, divIdData) {
	
	$.ajax({
		type:		"POST",
		url:		"../EwhExportDrugMaterial/PickDrugAjax?set_ajax_view",		
		dataType:   "json",	
		data : 		'reqExticketDetailId=' + reqExticketDetailId
				+	'&divIdData=' + divIdData,
		success: 	function(data) {
			if (data.error.code ==  'OK') {	
				$("div#pickDrugMaterialDialog").html(data.result);				
											
			} else {
				displayError(data.error.mess);				
			}		
		}
	});	
		
}